﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                    xmlns:controls="clr-namespace:CAION2.Controls"
                    xmlns:resources="clr-namespace:CAION2.Properties">

    <BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />

    <Style x:Key="{x:Type controls:SearchTextBox}" TargetType="{x:Type controls:SearchTextBox}">
        <Setter Property="Background" Value="Transparent" />
        <Setter Property="Foreground" Value="{DynamicResource InputText}" />
        <Setter Property="BorderThickness" Value="0" />
        <Setter Property="BorderBrush" Value="{DynamicResource InputBorder}" />
        <Setter Property="SnapsToDevicePixels" Value="True" />
        <Setter Property="LabelText" Value="{x:Static resources:Resources.RR_SearchText}" />
        <Setter Property="FocusVisualStyle" Value="{x:Null}" />
        <Setter Property="CaretBrush" Value="{DynamicResource InputText}" />
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type controls:SearchTextBox}">
                    <Border x:Name="ErrorBorder"
                            BorderBrush="Red"
                            BorderThickness="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                      Path=BorderThickness}">
                        <Border x:Name="border"
                                Background="{DynamicResource InputBackground}"
                                BorderBrush="{DynamicResource InputBorder}"
                                BorderThickness="1">
                            <Grid x:Name="LayoutGrid">
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="*" />
                                    <ColumnDefinition Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=ActualHeight}" />
                                </Grid.ColumnDefinitions>
                                <ScrollViewer x:Name="PART_ContentHost"
                                              Grid.Column="0"
                                              Margin="1"
                                              VerticalAlignment="Center" />
                                <Label x:Name="LabelText"
                                       Grid.Column="0"
                                       Margin="2"
                                       Content="{Binding RelativeSource={RelativeSource TemplatedParent},
                                                         Path=LabelText}"
                                       Foreground="{DynamicResource InputTextDisabled}"
                                       Padding="2,0,0,0" />
                                <Border x:Name="PART_SearchIconBorder"
                                        Grid.Column="1"
                                        HorizontalAlignment="Stretch"
                                        VerticalAlignment="Stretch"
                                        Background="Transparent"
                                        BorderThickness="0">
                                    <Path x:Name="SearchIcon"
                                          Width="12"
                                          Height="12"
                                          HorizontalAlignment="Center"
                                          VerticalAlignment="Center"
                                          Data="{StaticResource SearchIcon}"
                                          Fill="{DynamicResource InputText}"
                                          RenderTransformOrigin="0.5,0.5"
                                          Stretch="Uniform" />
                                </Border>
                            </Grid>
                        </Border>
                    </Border>
                    <ControlTemplate.Triggers>

                        <Trigger Property="IsMouseOver" Value="True">
                            <Setter TargetName="border" Property="Background" Value="{DynamicResource InputBackgroundHover}" />
                            <Setter TargetName="LabelText" Property="Foreground" Value="{DynamicResource InputTextHover}" />
                        </Trigger>

                        <Trigger Property="IsKeyboardFocusWithin" Value="True">
                            <Setter Property="BorderBrush" Value="{DynamicResource InputBorderHover}" />
                        </Trigger>

                        <Trigger Property="IsFocused" Value="True">
                            <Setter TargetName="LabelText" Property="Visibility" Value="Hidden" />
                        </Trigger>

                        <Trigger Property="HasText" Value="True">
                            <Setter TargetName="LabelText" Property="Visibility" Value="Hidden" />
                        </Trigger>

                        <Trigger SourceName="PART_SearchIconBorder" Property="IsMouseOver" Value="True">
                            <Setter TargetName="PART_SearchIconBorder" Property="Background" Value="{DynamicResource ButtonBackgroundHover}" />
                            <Setter TargetName="SearchIcon" Property="Fill" Value="{DynamicResource ButtonTextHover}" />
                        </Trigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition Property="HasText" Value="True" />
                                <Condition Property="SearchMode" Value="Instant" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="SearchIcon" Property="Data" Value="{StaticResource ClearIcon}" />
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_SearchIconBorder" Property="IsMouseOver" Value="True" />
                                <Condition Property="HasText" Value="True" />
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_SearchIconBorder" Property="Background" Value="{DynamicResource ButtonBackgroundHover}" />
                        </MultiTrigger>

                        <MultiTrigger>
                            <MultiTrigger.Conditions>
                                <Condition SourceName="PART_SearchIconBorder" Property="IsMouseOver" Value="True" />
                                <Condition Property="IsMouseLeftButtonDown" Value="True" />
                                <!--
                                    <Condition Property="HasText"
                                    Value="True" />
                                -->
                            </MultiTrigger.Conditions>
                            <Setter TargetName="PART_SearchIconBorder" Property="Background" Value="{DynamicResource ButtonBackgroundPressed}" />
                            <Setter TargetName="SearchIcon" Property="Fill" Value="{DynamicResource ButtonTextPressed}" />
                        </MultiTrigger>

                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
   
</ResourceDictionary>